21. Exercise: Implement Insert
Code Insert
Now it’s your turn to complete the insert() method!
Exercise Code
Exercise: T09.04-Exercise-Insert
Provider code
SOLUTION:
- Get writeable access to the task database
- Write URIMatching code to recognize the match for the tasks directory (which you'll insert data into)
- Write code to insert a row of data into the existing directory
- Set the value for the returned URI and write the default case
- Notify the ContentResolver if the URI has changed
UI code
SOLUTION:
- Put the text description and priority into a ContentValues object
- Use a ContentResolver to insert these values into the tasks directory
- Include a Toast to view the inserted content URI